﻿using UnityEngine;
using System.Collections;

public class Damage {
	public int hurt = 0; //伤害

	//计算伤害
	public static Damage Create(MilitaryUnit from, MilitaryUnit to)
	{
		Damage damage = new Damage();
		//根据目中率闪避率计算是否命中
		float hitTheTargetProbability = (float)from.attribute.hitProbability/(float)(from.attribute.hitProbability + to.attribute.missProbability);
		bool hitTaget = Random.Range(0, 1) >= hitTheTargetProbability;

		if (hitTaget){
			damage.hurt = from.attribute.attackPower - to.attribute.defancePower + Random.Range(0, from.attribute.attackPower/10);
			damage.hurt = Mathf.Max(1, damage.hurt);
		}

		return damage;
	}
}
